package com.ny.view;

import com.ny.entity.Manager;
import com.ny.entity.Order;
import com.ny.entity.Product;
import com.ny.entity.Student;
import com.ny.service.OrderService;
import com.ny.service.ProductService;
import com.ny.service.StudentService;
import com.ny.service.impl.OrderServiceImpl;
import com.ny.service.impl.ProductServiceImpl;
import com.ny.service.impl.StudentServiceImpl;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class ManagerView {
    ProductService productService = new ProductServiceImpl();

    public ManagerView() throws SQLException, ClassNotFoundException {
    }
    OrderService  orderService = new OrderServiceImpl();
    StudentService  studentService = new StudentServiceImpl();
public void managerView(Manager manager) throws SQLException {
    System.out.println("请选择相应操作");
    System.out.println("1.商品管理");
    System.out.println("2.订单管理");
    System.out.println("3.用户管理");
    Scanner scanner = new Scanner(System.in);
    int choice = scanner.nextInt();
    switch (choice) {
        case  1:
            System.out.println("1.查看所有商品");
            System.out.println("2.添加商品");
            System.out.println("3.修改商品信息");
            System.out.println("4.删除商品");
            System.out.println("5.返回");
            while (true) {
                Scanner scanner1 = new Scanner(System.in);
                int choice1 = scanner1.nextInt();
                switch (choice1) {
                    case 1:
                        List<Product> productList = productService.findAllProduct();
                        System.out.println("商品序号" + "\t" + "商品名称" + "\t" + "商品价格" + "\t" + "商品库存" + "\t" + "商品类别" + "\t" + "商品描述");
                        for (Product product : productList) {
                            System.out.println("\t");
                            System.out.print(product.getProduct_id());
                            System.out.print("\t" + "\t");
                            System.out.print(product.getName());
                            System.out.print("\t" + "\t");
                            System.out.print(product.getPrice());
                            System.out.print("\t" + "\t");
                            System.out.print(product.getStock());
                            System.out.print("\t" + "\t");
                            System.out.print(product.getCategory());
                            System.out.print("\t" + "\t");
                            System.out.print(product.getDescription());
                        }
                        break;
                    case 2:
                        System.out.println("请输入商品名称");
                        String name = scanner.next();
                        System.out.println("请输入商品价格");
                        double price = scanner.nextDouble();
                        System.out.println("请输入商品库存");
                        int stock = scanner.nextInt();
                        System.out.println("请输入商品类别");
                        String category = scanner.next();
                        System.out.println("请输入商品描述");
                        String description = scanner.next();
                        Product product = new Product();
                        product.setName(name);
                        product.setPrice(price);
                        product.setStock(stock);
                        product.setCategory(category);
                        product.setDescription(description);
                        int add = productService.addProduct(product);
                        if (add > 0) {
                            System.out.println("添加成功");
                        }
                        break;
                    case 3:
                        System.out.println("请输入商品编号");
                        int productId = scanner.nextInt();
                        System.out.println("请输入商品名称");
                        String name1 = scanner.next();
                        System.out.println("请输入商品价格");
                        double price1 = scanner.nextDouble();
                        System.out.println("请输入商品库存");
                        int stock1 = scanner.nextInt();
                        System.out.println("请输入商品类别");
                        String category1 = scanner.next();
                        System.out.println("请输入商品描述");
                        String description1 = scanner.next();
                        Product product1 = new Product();
                        product1.setProduct_id(productId);
                        product1.setName(name1);
                        product1.setPrice(price1);
                        product1.setStock(stock1);
                        product1.setCategory(category1);
                        product1.setDescription(description1);
                        int update = productService.updateProduct(product1);
                        if (update > 0) {
                            System.out.println("修改成功");
                        }

                        break;
                    case 4:
                        System.out.println("请输入商品编号");
                        int productId1 = scanner.nextInt();
                        int delete = productService.deleteProduct(productId1);
                        if (delete > 0) {
                            System.out.println("删除成功");
                        }
                        break;
                    case 5:
                        return;



                        }
                }
            case 2:
                System.out.println("1.查看所有订单");
                System.out.println("2.修改订单");
                System.out.println("3.删除订单");
                System.out.println("4.返回");
                while (true) {
                    Scanner scanner2 = new Scanner(System.in);
                    int choice2 = scanner2.nextInt();
                    switch (choice2) {
                        case 1:
                            List<Order> orderList = orderService.findAllOrder();
                            System.out.println("订单编号" + "\t" + "商品编号" + "\t" + "学生编号" + "\t" + "订单数量" + "\t" + "订单总价");
                            for (Order order : orderList) {
                                System.out.println("\t");
                                System.out.print(order.getOrder_id());
                                System.out.print("\t"+"\t");
                                System.out.print(order.getProduct_id());
                                System.out.print("\t"+"\t");
                                System.out.print(order.getStudent_id());
                                System.out.print("\t"+"\t");
                                System.out.print(order.getNumber());
                                System.out.print("\t"+"\t");
                                System.out.print(order.getTotal_price());
                            }
                            case 2:
                                System.out.println("请输入订单编号");
                                int orderId = scanner.nextInt();
                                System.out.println("请输入商品编号");
                                int productId = scanner.nextInt();
                                System.out.println("请输入学生编号");
                                int studentId = scanner.nextInt();
                                System.out.println("请输入订单数量");
                                String number = scanner.next();
                                System.out.println("请输入订单总价");
                                double total_price = scanner.nextDouble();
                                Order order = new Order();
                                order.setOrder_id(orderId);
                                order.setProduct_id(productId);
                                order.setStudent_id(studentId);
                                order.setNumber(number);
                                order.setTotal_price(total_price);
                                int update = orderService.updateOrder(order);
                                if (update > 0) {
                                    System.out.println("修改成功");
                                }
                            break;
                                case 3:
                                    System.out.println("请输入订单编号");
                                    int orderId1 = scanner.nextInt();
                                    int delete = orderService.deleteOrder(orderId1);
                                    if (delete > 0) {
                                        System.out.println("删除成功");
                                    }
                                    break;
                                    case 4:
                                        return;
                    }
                }
                case 3:
                    System.out.println("1.查看所有学生");
                    System.out.println("2.修改学生信息");
                    System.out.println("3.删除学生");
                    while (true) {
                        Scanner scanner3 = new Scanner(System.in);
                        int choice3 = scanner3.nextInt();
                        switch (choice3) {
                            case 1:
                                List<Student> studentList = studentService.findAllStudent();
                                System.out.println("学生编号" + "\t" + "学生姓名" + "\t" + "学生手机号" + "\t" + "学生密码");
                                for (Student student : studentList) {
                                    System.out.println("\t");
                                    System.out.print(student.getStudentId());
                                    System.out.print("\t"+"\t");
                                    System.out.print(student.getStudentName());
                                    System.out.print("\t"+"\t");
                                    System.out.print(student.getStudentPhone());
                                    System.out.print("\t"+"\t");
                                    System.out.print(student.getStudentPassword());
                                }
                                break;
                                case 2:
                                    System.out.println("请输入学生编号");
                                    int studentId = scanner.nextInt();
                                    System.out.println("请输入学生姓名");
                                    String studentName = scanner.next();
                                    System.out.println("请输入学生手机号");
                                    String studentPhone = scanner.next();
                                    System.out.println("请输入学生密码");
                                    String studentPassword = scanner.next();
                                    Student student1 = new Student();
                                    student1.setStudentId(studentId);
                                    student1.setStudentName(studentName);
                                    student1.setStudentPhone(studentPhone);
                                    student1.setStudentPassword(studentPassword);
                                    int update = studentService.update(student1);
                                    if (update > 0) {
                                        System.out.println("修改成功");
                                    }
                                    break;
                                    case 3:
                                        System.out.println("请输入学生编号");
                                        int studentId1 = scanner.nextInt();
                                        int delete = studentService.delete(studentId1);
                                        if (delete > 0) {
                                            System.out.println("删除成功");
                                        }
                                        break;
                        }

                    }
            }

    }


    }




